package client // Package client import "xemo.top/docker/docker/client"
import (
	"context"
	"net/url"
	"strconv"
	"xemo.top/docker/docker/api/types"
)

// ContainerResize 更改容器的tty大小
// ContainerResize changes the size of the tty for a container
func (cli *Client) ContainerResize(ctx context.Context, containerID string, options types.ResizeOptions) error {
	return cli.resize(ctx, "/containers/"+containerID, options.Height, options.Width)
}

func (cli *Client) resize(ctx context.Context, basePath string, height, width uint) error {
	query := url.Values{}
	query.Set("h", strconv.Itoa(int(height)))
	query.Set("w", strconv.Itoa(int(width)))
	resp, err := cli.post(ctx, basePath+"/resize", query, nil, nil)
	defer ensureReaderClosed(resp)
	return err
}
